<?php
namespace Home\Controller;

use Wechat\Wechat;
use Wechat\WechatAuth;

/**
 * 微信入口
 */
class WebWechatController extends HomeController
{

    private $wechat; // 微信对象
    private $wechatAuth; // 微信对象

    public function __construct()
    {
        parent::__construct();
        $token = 'zhibenjiaweixin'; //微信后台填写的TOKEN
        /* 加载微信SDK */
        try {
            // $this->wechat = new Wechat($token);
            $this->wechatAuth = new wechatAuth('wx737d2e33c724c999', '3f62fcaba97e4fcfd3b4321f253c32ed');
        } catch (\Exception $e) {
            var_dump('wechat 失败!');
        }
    }

    public function index()
    {
        $code = I('code');
        $token = $this->wechatAuth->getAccessToken('code', $code);
        dd($token);
        $userData = $this->wechatAuth->getUserInfo($token['openid']);
        dd($userData);
        // $this->wechat
    }

    public function getUserInfo()
    {
        echo "<pre>";
        print_r($_REQUEST);
        
        $WechatAddons = A("Addons://Wechat/Wechat");
        $wechatAuthArr = $WechatAddons->getUserInfo();

        print_r($wechatAuthArr);
        print_r($wechatAuthArr);
        print_r($wechatAuthArr);
        echo "</pre>";
    }



}